package com.huaonline.music.player.adapter;

import java.util.ArrayList;
import java.util.Map;

import com.huaonline.music.player.R;
import com.huaonline.music.player.commonutils.FileCommonUtil;
import com.huaonline.music.player.commonutils.ToastCommonUtils;


import android.content.ContentValues;
import android.content.Context;
import android.database.DataSetObserver;
import android.media.RingtoneManager;
import android.net.Uri;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.ImageButton;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class MusicListAdapter extends BaseAdapter implements View.OnClickListener{

	private ArrayList<Map<String, String>> music_data;
	private Context ctx;
	

	public MusicListAdapter(Context ctx) {
		music_data = new ArrayList<Map<String, String>>();
		this.ctx = ctx;
	}

	public MusicListAdapter(Context ctx, ArrayList<Map<String, String>> data) {
		music_data = data;
		this.ctx = ctx;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return music_data.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return music_data.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater mInflater = LayoutInflater.from(ctx);

		convertView = mInflater.inflate(R.layout.music_layout,null);
		ImageButton setIB=(ImageButton) convertView.findViewById(R.id.set_musiclist_main_ib);
		setIB.setOnClickListener(this);
		setIB.setOnTouchListener(new View.OnTouchListener() {
			
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				getPosition(event.getX(), event.getY());
				return false;
			}
		});
		TextView nameTV=(TextView) convertView.findViewById(R.id.fname_musiclist_nameTV);
		TextView pathTV=(TextView) convertView.findViewById(R.id.fpath_musiclist_pathTV);
		String name = music_data.get(position).get(FileCommonUtil.AUDIO_NAME);
		String path = music_data.get(position).get(FileCommonUtil.AUDIO_NAME);
		pathTV.setText(path);
		nameTV.setText(name);
		return convertView;
	}


	



	private void getPosition(float x,float y){
		ToastCommonUtils.getToastShort(" x="+x+",  y="+y+" " , ctx);
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}


}
